<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>后台管理系统</title>
    <meta name="author" content="BaiYY"/>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="renderer" content="webkit">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap-datetimepicker.min.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/pages.css"/>
    <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/time.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/pages.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
</head>
<body>
    <div class="right-sidebar" style="max-width: 1200px;">
        <ul class="nav nav-tabs" style="margin-bottom: 16px" role="tablist">
            <li role="presentation" class="active" ><a href="myNextLog.html">日志消耗</a></li>
            <li role="presentation"id="expends"><a href="myNextexpendTotal.html">{:L(GAME_EXPEND_TOTAL)}</a></li>
        </ul>
        <p>
            <h3>说明：</h3>
            <p>可手动输入查询的时间段，默认是15天内的数据</p>
        </p>

        <div class="input-group" style="margin-top: 20px">
            <span class="input-group-addon">游戏UID&nbsp;</span>
            <input class="form-control" name="uid" type="text" id="uid"/>
        </div>
        <div class="input-group">
            <span class="input-group-addon">开始时间</span>
            <input type="text" class="form-control" id="start_time" name="start_time" data-date-format="yyyy-mm-dd hh:ii:ss">
        </div>
        <div class="input-group">
            <span class="input-group-addon" >结束时间</span>
            <input type="text" class="form-control" id="end_time" name="end_time" data-date-format="yyyy-mm-dd hh:ii:ss">
        </div>
        <div class="text-center" style="margin: 20px auto"> <button class="btn btn-primary" id="cbtn">&emsp;查询&emsp;</button></div>

        <div class="table-responsive">
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>游戏UID</th>
                    <th>更改数量</th>
                    <th>剩余数量</th>
                    <th>更改原因</th>
                    <th>更改时间</th>
                </tr>
                </thead>
                <tbody id="dataList"></tbody>
            </table>
        </div>
        <ul class="page" id="page" style="width: 100%;overflow: hidden;"></ul>
    </div>
    <script type="text/javascript">

        $(function () {
            var expends = $.trim($("#expends").text());
            if(expends == 'GAME_EXPEND_TOTAL' || expends == '') {
                $("#expends").hide();
            }
            $("#end_time").val(getLocalTime(new Date()/1000));
            $("#start_time").val(getLocalTime((new Date()/1000 - 1296000)));

            $( "#start_time" ).datetimepicker({
                language: 'zh-CN',
                autoclose: 1,
                todayHighlight: 1,
                weekStart: 1,
                startDate: 0
            });
            $( "#end_time" ).datetimepicker({
                language: 'zh-CN',
                autoclose: 1,
                todayHighlight: 1,
                weekStart: 1,
                startDate: 0
            });
        });
        $("#uid").blur(function () {
            var user_id = "<?php echo session('adminTel');?>";
            var uid = $.trim($("#uid").val());
            if(uid == '' || uid == ''){
                alert("请输入要查询的代理ID!");
                return false;
            }else if(isNaN($.trim(user_id))){
                alert("代理ID是数字!");
                window.location.href="{:U('Admin/Main/myNextLog')}";
                return false;
            }else if(uid == user_id) {
                alert("抱歉，不能输入自己的ID");
                window.location.href="{:U('Admin/Main/myNextLog')}";
                return false;
            }

            $.ajax({
                type:'get',
                url:"{:U('Admin/Main/myNextChecked')}?uid="+uid,
                success: function (data) {
                    if(data == 'unexist') {
                        alert("该UID不存在");
                        window.location.href = "{:U('Admin/Main/myNextLog')}";
                    }else if(data == 'notagent') {
                        alert("该UID不是你的代理");
                        window.location.href = "{:U('Admin/Main/myNextLog')}";
                    }else if(data == 'error') {
                        alert("请求错误！");
                        window.location.href="{:U('Admin/Main/myNextLog')}";
                    }else if(data == 'admin') {
                        alert("不能查询管理员的日志");
                        window.location.href="{:U('Admin/Main/myNextLog')}";
                    }
                }
            })
        })
        
        $("#cbtn").on("click",function () {
            var uid = $("#uid").val();
            var start_time = new Date($("#start_time").val()).getTime()/1000;
            var end_time = new Date($("#end_time").val()).getTime()/1000;

            if(start_time > end_time || start_time == end_time) {
                alert("请注意时间的先后顺序！");
                window.location.href="{:U('Admin/Main/myNextLog')}";
                return false;
            }

            $.ajax({
                type:"post",
                url:"{:U('Admin/Main/myNextLogDetail')}",
                dataType:"json",
                data:{'uid':uid,'start_time':start_time,'end_time':end_time},
                success: function (datas) {
                    console.log(datas);
                    if(datas == 'nodata') {
                        $("#dataList").html("暂时没查到任何信息！");
                    }else{
                        if(datas.arr == '') {
                            $("#dataList").html("暂时没查到任何信息！");
                        }else{
                            options= {
                                "id":"page",//显示页码的元素
                                "data":datas.arr,//显示数据
                                "maxshowpageitem":2,//最多显示的页码个数
                                "pagelistcount":10,//每页显示数据个数
                                "callBack": function (data) {
                                    var str = '';
                                    var res = '';
                                    for(var i=0;i<data.length;++i){
                                        if(data[i].card > 0) {
                                            data[i].card = "+"+Math.abs(data[i].card);
                                        }else if(data[i].card < 0) {
                                            data[i].card = '-' + Math.abs(data[i].card);
                                        }
                                        switch (data[i].r) {
                                            case 'pay':
                                                res = '{:L(GAME_PAY)}';
                                                break;
                                            case 'payTo':
                                                res = '{:L(GAME_PAYTO)}';
                                                break;
                                            case 'gmAdd':
                                                res = '{:L(GAME_ADD)}';
                                                break;
                                            case 'gmAlter':
                                                res = '{:L(GAME_ALTER)}';
                                                break;
                                            case 'exchangeCoin':
                                                res = '{:L(GAME_EXCHANGE)}';
                                                break;
                                            case 'roomFinished':
                                                res = '{:L(GAME_ROOM)}';
                                                break;
                                            case 'SevenDayReward':
                                                res = '{:L(GAME_REWARD)}';
                                                break;
                                            case 'initResource':
                                                res = '{:L(GAME_INIT)}';
                                                break;
                                            case 'shareReward':
                                                res = '{:L(GAME_SHARE)}';
                                                break;
                                            case 'XYBBKGameCost':
                                                res = '{L(GAME_LUCK)}';
                                                break;
                                            default:
                                                res = data[i].r
                                        }
                                        str += "<tr><td>"+data[i].uid+"</td><td>"+data[i].card+"</td><td>"+data[i].s.card+"</td><td>"+res+"</td><td>"+data[i].t+"</td></tr>";
                                    }
                                    $("#dataList").html(str);
                                }
                            }
                            page.init(datas.arr.length,1,options);
                        }
                    }
                }
            })
        })
    </script>
</body>
</html>